package com.kanche.bigbaby.activity;

import android.content.Context;
import android.os.Bundle;
import android.os.Vibrator;

import com.kanche.bigbaby.R;
import com.kanche.bigbaby.support.swipebackLayout.SwipeBackLayout;
import com.kanche.bigbaby.support.swipebackLayout.app.SwipeBackActivity;

/**
 * Created by Chenshao_Young on 15/5/20.
 */
public class MoreActivity extends SwipeBackActivity {

    private static final int VIBRATE_DURATION = 20;
    SwipeBackLayout swipeBackLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_more);

        swipeBackLayout = getSwipeBackLayout();
        swipeBackLayout.setEdgeTrackingEnabled(SwipeBackLayout.EDGE_LEFT);

        swipeBackLayout.addSwipeListener(new SwipeBackLayout.SwipeListener() {
            @Override
            public void onScrollStateChange(int state, float scrollPercent) {

            }

            @Override
            public void onEdgeTouch(int edgeFlag) {

                vibrate(VIBRATE_DURATION);
            }

            @Override
            public void onScrollOverThreshold() {
                vibrate(VIBRATE_DURATION);
            }
        });

    }

    private void vibrate(long duration) {
        Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        long[] pattern = {
                0, duration
        };
        vibrator.vibrate(pattern, -1);
    }
}
